<?php

/**
 * @version     $Id: view.php 3 2010-10-08 17:49:35Z obalyuk87@gmail.com $
 * @package     AdminSafe
 * @subpackage
 * @copyright   Copyright (C) 2010 Oleksandr Balyuk (www.boolcast.com)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL v2
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */
// No direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.view');
jimport('joomla.html.toolbar');

/**
 * Purpose of this view is to create and enforce programming standard
 * throughtout the component for the format and behavior of the view
 *
 * @abstract
 * @author Oleksandr Balyuk <obalyuk@boolcast.com>
 */
abstract class AdminsafeView extends JView {

    /**
     * Display the View
     *
     * @param string $tpl
     */
    public function display($tpl = null) {

        //
        $this->_loadData();
        $this->_prepareDataForDisplay();

        //
        $this->_setToolBar();
        $this->_addStylesheetsAndScripts();

        //
        parent::display($tpl);
    }

    /**
     * Adds Back to CPanel Button to the toolbar
     */
    protected function _addBackToCPanelButton() {
        $text = JText::_('CPanel');
        $href = JRoute::_('index.php?option=com_adminsafe');
        $bar = JToolBar::getInstance('toolbar');
        if ($bar) {
            $bar->appendButton('Link', 'config', $text, $href);
        }
    }

    /**
     * Sets the toolsbar. Title, icon, buttons, etc...
     *
     * @return void
     */
    abstract protected function _setToolBar();

    /**
     * Adds stylesheets and scripts to the document
     *
     * @return void
     */
    abstract protected function _addStylesheetsAndScripts();

    /**
     * Loads data from the model
     *
     * @return void
     */
    abstract protected function _loadData();

    /**
     * Prepares data loaded by _loadData() for display
     *
     * @return void
     */
    abstract protected function _prepareDataForDisplay();
}